/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.model.bean;

import com.entites.Employee;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
public class EmployeeFacade extends AbstractFacade<Employee> implements EmployeeFacadeLocal {

    @PersistenceContext(unitName = "BluePumpkinCompanyPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public EmployeeFacade() {
        super(Employee.class);
    }

    @Override
    public List<Employee> findAllEmployeeTnviteEvent(int eventId,String usn) {
        Query query = em.createNamedStoredProcedureQuery("EventLibrary.InvitedAttendEvent");
        query.setParameter("eventId", eventId);
        query.setParameter("username", usn);
        List<Employee> list = new ArrayList<>();
        List<Object[]> obj = query.getResultList();
        for (Object[] row : obj) {
            String avatar = (String) row[0];
            String username = (String) row[1];
            String staus = (String) row[2];

            Employee emp = new Employee(avatar, username, staus);
            list.add(emp);
        }
        return list;
    }

}
